home *** CD-ROM | disk | FTP | other *** search
- unit Filelstu;
-
- interface
-
- uses
- WinTypes, WinProcs, SysUtils, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls;
-
- type
- TForm1 = class(TForm)
- Memo1: TMemo;
- procedure Memo1DblClick(Sender: TObject);
- private
- { Private declarations }
- public
- procedure MyCallBack(const Directory: String);
- end;
-
- TCallBack = procedure(const Directory: String) of object;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.MyCallBack(const Directory: String);
- begin
- Memo1.Lines.Add(Directory);
- Caption := IntToStr(Memo1.Lines.Count);
- Application.ProcessMessages;
- end;
-
- procedure GetSubDirs(const Dir: String; CallBack: TCallBack);
- var
- SearchRec: TSearchRec;
- ThisDir: String;
- begin
- if FindFirst(Dir + '\*.*', faDirectory, SearchRec) = 0 then
- try
- repeat
- { Only want directories }
- if (SearchRec.Attr and faDirectory <> 0) and
- { Don't want current or parent directory }
- (SearchRec.Name[1] <> '.') then
- begin
- ThisDir := Dir + '\' + SearchRec.Name;
- if Assigned(CallBack) then
- CallBack(ThisDir);
- GetSubDirs(ThisDir, CallBack);
- end;
- until (FindNext(SearchRec) <> 0) or Application.Terminated;
- finally
- FindClose(SearchRec);
- end;
- end;
-
- procedure TForm1.Memo1DblClick(Sender: TObject);
- begin
- Memo1.Lines.Clear;
- Memo1.Lines.BeginUpdate;
- GetSubDirs('c:', MyCallBack);
- Memo1.Lines.EndUpdate;
- end;
-
- end.
-